package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Slides;
import com.ww.sound_emission.service.SlidesService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/slides")
public class SlideController {

    @Autowired
    private SlidesService slideService;

    // 获取所有轮播图
    @GetMapping
    public Result<List<Slides>> getAllSlides() {
        List<Slides> slides = slideService.list();
        return Result.success(slides);
    }

    // 添加轮播图
    @PostMapping
    public Result<String> addSlide(@RequestBody Slides slide) {
        slideService.save(slide);
        return Result.success("轮播图添加成功");
    }

    // 删除轮播图
    @DeleteMapping("/{id}")
    public Result<String> deleteSlide(@PathVariable Long id) {
        slideService.removeById(id);
        return Result.success("轮播图删除成功");
    }
}